package pl.edu.agh.pros.internal.proxy;

import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.edu.agh.pros.conf.ProxyConfiguration;
import pl.edu.agh.pros.internal.interf.Disposable;

import com.google.common.base.Preconditions;

public abstract class AbstractProxyNode extends AbstractNodeMain implements Disposable {

	private static final Logger logger = LoggerFactory.getLogger(AbstractProxyNode.class);

	protected final ProxyDispatcher proxyDispatcher;
	protected final ProxyConfiguration proxyNodeConfiguration;
	protected ConnectedNode node;

	public AbstractProxyNode(ProxyDispatcher proxyDispatcher, ProxyConfiguration proxyNodeConfiguration) {
		Preconditions.checkNotNull(proxyDispatcher);
		Preconditions.checkNotNull(proxyNodeConfiguration);

		this.proxyDispatcher = proxyDispatcher;
		this.proxyNodeConfiguration = proxyNodeConfiguration;
	}

	@Override
	public void onShutdownComplete(Node node) {
		this.node = null;
	}

	@Override
	public void onError(Node node, Throwable throwable) {
		logger.error(node.toString(), throwable);
	}

}
